package com.cardone.common.beans.propertyeditors;

import java.text.DateFormat;
import java.text.ParseException;

import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.StringUtils;

import com.cardone.common.util.DateUtils;

/**
 * 自定义时间绑定
 *
 * @author fand.cardone
 *
 */
@Slf4j
public class CustomDateEditor extends org.springframework.beans.propertyeditors.CustomDateEditor {
	public CustomDateEditor(final DateFormat dateFormat, final boolean allowEmpty) {
		super(dateFormat, allowEmpty);
	}

	public CustomDateEditor(final DateFormat dateFormat, final boolean allowEmpty, final int exactDateLength) {
		super(dateFormat, allowEmpty, exactDateLength);
	}

	@Override
	public void setAsText(final String text) throws IllegalArgumentException {
		if (StringUtils.isBlank(text)) {
			return;
		}

		try {
			this.setValue(DateUtils.parseDate(text));
		} catch (final ParseException e) {
			CustomDateEditor.log.error(e.getMessage(), e);
		}
	}
}
